<template>
  <div class="page">
    <!-- 搜索区域 开始 -->
    <div class="el_card_box">
      <el-form :inline="true" size="small" :model="formInline" class="search_form">
        <el-form-item label="医院：">
          <hospital-select v-model="formInline.belongOrg"></hospital-select>
        </el-form-item>
        <el-form-item label="操作时间：">
          <el-date-picker v-model="orderTime" type="daterange" range-separator="至" start-placeholder="开始日期"
            end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="操作内容：">
          <el-select v-model="formInline.action" filterable placeholder="请选择">
            <el-option v-for="(item, index) in optionsList" :key="index" :label="item.name" :value="item.name"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关键词：">
          <el-input v-model="formInline.operator" placeholder="姓名 | 手机 | IP"></el-input>
        </el-form-item>
      </el-form>
      <div class="search_btn_box">
        <el-button type="primary" size="small" @click="onSearch">筛选</el-button>
        <el-button type="default" size="small" @click="rest">清空筛选</el-button>
      </div>
    </div>
    <!-- 搜索区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">
      <!-- <div class="action_box">
        <el-button type="primary" size="small" :loading="eloading" @click="downloadExcel('addDialog')">导出excel</el-button>
      </div> -->
      <el-table ref="elTable" class="el_table" size="small" :data="tableData">
        <el-table-column prop="orgzName" label="医院名称" show-overflow-tooltip />
        <el-table-column prop="username" label="姓名" show-overflow-tooltip />
        <el-table-column prop="operator" label="登录手机" show-overflow-tooltip />
        <el-table-column prop="panType" label="账号类型" show-overflow-tooltip />
        <el-table-column prop="createdDate" label="操作时间" show-overflow-tooltip />
        <el-table-column prop="remark" label="操作内容" show-overflow-tooltip />
        <el-table-column prop="platform" label="登录平台" show-overflow-tooltip />
        <el-table-column prop="ip" label="IP" show-overflow-tooltip />
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize"
          :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList"
          @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->

  </div>
</template>
  
<script>
import {
  GETLOGGINSEARCH,
  GETLOGGINOPTIONS,
  GETLOGGINEXPORT,
} from "@/http/system";
import { broadcast, deepClone, showModal } from "@/common/util";
import { exportExcel } from "@/common/common";
import { GET_HOSPITAL_LOGGINLIST } from '@/http/hospital'
import moment from 'moment';
export default {
  data() {
    return {
      formInline: {},
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 30, 40],
      pageSize: 10,
      loading: false,
      current: {},
      orderTime: [],
      optionsList: [],
      eloading: false,
    };
  },
  mounted() {
    let _start = moment().format('yyyy-MM-DD');
    let _end = moment().subtract(7, 'day').format('yyyy-MM-DD');
    console.log(_start, _end);
    this.orderTime = [_end,_start];
    this.getOptions();
    this.getList();
  },
  methods: {
    /** 重置 */
    rest() {
      this.formInline = {};
      this.orderTime = [];
      this.getList();
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取参数 */
    getParams() {
      let oParams = JSON.parse(JSON.stringify(this.formInline));
      let n = this.orderTime;

      if (n && n.length > 0) {
        oParams.sDate = n[0];
        oParams.eDate = n[1];
      }

      oParams.pageNumber = this.pageNumber;
      oParams.pageSize = this.pageSize;
      return oParams;
    },

    /** 获取列表 */
    getList() {
      let _this = this;
      let oParams = this.getParams();
      GET_HOSPITAL_LOGGINLIST(oParams).then((res) => {
        let obj = res.data || {};
        _this.tableData = obj.list || [];
        _this.pageTotal = obj.totalElements;
      });
    },

    // 查看用户信息
    lookUser(row) {
      console.log(JSON.parse(row.requestData));
      if (row.requestData) {
        let m = JSON.parse(row.requestData);
        let id = m[0];
        let options = deepClone(row);
        options.id = m[0];
        broadcast("userDetail", options);
      }
    },

    // 获取下拉列表
    getOptions() {
      GETLOGGINOPTIONS().then((res) => {
        this.optionsList = res.data || [];
      });
    },

    // 导出excel
    downloadExcel() {
      let _this = this;
      let o = deepClone(_this.formInline);
      let m = Object.keys(o);
      if (m.length > 0) {
        showModal({
          message: "确定是否导出筛选条件下面所有日志列表?",
          showCancelButton: true,
          type: "warning",
          success: function () {
            _this.dowloadExcelFile();
          },
        });
        return false;
      }

      _this.dowloadExcelFile();
    },

    // 下载excel
    dowloadExcelFile() {
      let _this = this;
      let oParams = _this.getParams();
      let options = {};

      delete oParams.pageNumber;
      delete oParams.pageSize;

      options.method = "GET";
      options.data = oParams;
      options.url = GETLOGGINEXPORT;
      options.fileName = "日志列表.xlsx";
      _this.eloading = true;
      exportExcel(options).then((res) => {
        _this.eloading = false;
      });
    },

    // 搜索
    onSearch() {
      this.pageNumber = 1;
      this.getList()
    }
  },
};
</script>
  
<style lang="scss" scoped>
@import "@/assets/style/customer/index.scss";

.action_box {
  margin: 0 0 10px 0;
}</style>
  